<template>
  <div class="base-container" id="main">
    <t-steps :current="activeForm" status="process" :onChange="onCurChanged">
      <t-step-item title="基本信息" :content="isSubmit('platformId')">
      </t-step-item>
      <t-step-item title="平台主要人员" :content="isSubmit('unitId')"></t-step-item>
      <t-step-item title="现有仪器及设备一览表（20万元以上）" :content="isSubmit('equipmentId')"></t-step-item>
      <t-step-item title="管理委员会成员" :content="isSubmit('backgroundId')"></t-step-item>
      <t-step-item title="学术委员会成员" :content="isSubmit('budgetId')"></t-step-item>
      <t-step-item title="相关附件" :content="isSubmit('fileId')"></t-step-item>
    </t-steps>
    <t-loading text="加载中..." :fullscreen="false" attach="#main" :loading="applyLoading" size="medium">
    </t-loading>
    <!-- 基本信息 -->
    <t-form ref="form" :key="activeForm" :colon="true" v-if="activeForm === 0" class="step-form" :data="formData0"
      @submit="onSubmit0" :rules="rules0" label-width="200px">
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">

          <t-card class="step-card" size="small" title="基本信息">
            <t-row style="align-items: stretch" :gutter="14">
              <t-col :span="6">
                <t-form-item label="平台名称" name="name">
                  <t-input clearable style="width: 390px" v-model="formData0.name"></t-input>
                </t-form-item>
                <t-form-item label="平台类型" name="platformCategory">
                  <t-select clearable style="width: 390px" v-model="formData0.platformCategory"
                    :options="dict.type.platform_category">
                  </t-select>
                </t-form-item>
                <t-form-item label="技术领域" name="technicalField">
                  <t-select clearable style="width: 390px" v-model="formData0.technicalField"
                    :options="dict.type.platform_technical_field">
                  </t-select>
                </t-form-item>
                <t-form-item label="组建方式" name="constructionMode">
                  <t-select clearable style="width: 390px" v-model="formData0.constructionMode"
                    :options="dict.type.construction_mode">
                  </t-select>
                </t-form-item>
                <t-form-item label="申报方式" name="declarationMethod">
                  <t-select clearable style="width: 390px" v-model="formData0.declarationMethod"
                    :options="dict.type.declaration_method">
                  </t-select>
                </t-form-item>
                <t-form-item label="申报日期" name="declarationDate">
                  <t-date-picker clearable style="width: 390px" v-model="formData0.declarationDate"></t-date-picker>
                </t-form-item>
                <t-form-item label="主管部门" name="manageDept">
                  <t-input clearable style="width: 390px" v-model="formData0.manageDept"></t-input>
                </t-form-item>
              </t-col>
              <t-col :span="6">
                <t-form-item label="依托单位" name="deptName">
                  <t-input clearable disabled style="width: 390px" v-model="currentDeptName"></t-input>
                </t-form-item>
                <t-form-item label="通讯地址" name="address">
                  <t-input clearable style="width: 390px" v-model="formData0.address"></t-input>
                </t-form-item>
                <t-form-item label="邮编" name="postCode">
                  <t-input clearable style="width: 390px" v-model="formData0.postCode"></t-input>
                </t-form-item>
                <t-form-item label="平台服务行业" name="serviceIndustry">
                  <t-input clearable style="width: 390px" v-model="formData0.serviceIndustry"></t-input>
                </t-form-item>
                <t-form-item label="平台研究方向所属学科" name="owningSubject">
                  <t-select clearable style="width: 390px" v-model="formData0.owningSubject"
                    :options="dict.type.kjpt_owning_subject">
                  </t-select>
                </t-form-item>
                <t-form-item label="项目开始日期" name="startDate">
                  <t-date-picker clearable style="width: 390px" v-model="formData0.startDate"></t-date-picker>
                </t-form-item>
                <!-- <t-form-item label="平台建设内容" name="intro">
                  <t-textarea style="width: 390px" clearable tips="不超过200字" :maxlength="200" :autosize="{ minRows: 3 }"
                    v-model="formData0.intro" placeholder="请输入内容" />
                </t-form-item> -->
              </t-col>
              <t-row style="margin-top: 20px;">
                <t-col :span="12">
                  <t-form-item name="intro" label="平台建设内容">
                    <tiny-mce-editor v-model="formData0.intro"></tiny-mce-editor>
                  </t-form-item>
                </t-col>
              </t-row>
            </t-row>
          </t-card>
        </t-col>
        <t-col :span="12" style="margin-top: 20px;">
          <t-row style="align-items: stretch" :gutter="14">
            <t-col :span="6">
              <t-card class="step-card" size="small" title="平台联系人">
                <t-form-item label="姓名" name="platformLinker.name">
                  <t-select v-model="formData0.platformLinker.name" creatable filterable @change="onLeaderNameChange2"
                    placeholder="请输入姓名" :loading="leaderLoading2" @search="remoteProjectLeaderMethod2"
                    :options="nameOptions2" @create="createProjectLeaderOptions2" style="width: 390px" />
                </t-form-item>
                <t-form-item label="手机号码" name="platformLinker.phone">
                  <t-input style="width: 390px" placeholder="请输入手机号码" clearable
                    v-model="formData0.platformLinker.phone"></t-input>
                </t-form-item>
                <t-form-item label="电子信箱" name="platformLinker.email">
                  <t-input style="width: 390px" clearable v-model="formData0.platformLinker.email"></t-input>
                </t-form-item>
              </t-card>
            </t-col>
            <t-col :span="6">
              <t-card class="step-card" size="small">
                <template #title>
                  平台主要研究方向：
                </template>
                <t-form-item name="researchDirections">
                  <contract-terms ref="contract-terms" v-model="formData0.researchDirections"
                    :editOpen="true"></contract-terms>
                </t-form-item>
              </t-card>
            </t-col>
          </t-row>
        </t-col>
      </t-row>
      <t-row style="align-items: stretch" :gutter="14">
        <t-col :span="12">
          <t-card class="step-card" size="small" title="平台负责人">
            <t-row>
              <t-col :span="6">
                <t-form-item label="姓名" name="platformLeader.name">
                  <t-select v-model="formData0.platformLeader.name" creatable filterable @change="onLeaderNameChange"
                    placeholder="请输入姓名" :loading="leaderLoading" @search="remoteProjectLeaderMethod"
                    :options="nameOptions" @create="createProjectLeaderOptions" style="width: 390px" />
                </t-form-item>
                <t-form-item label="性别" name="platformLeader.sex">
                  <t-select style="width: 390px" placeholder="请选择性别" :options="dict.type.sys_user_sex"
                    v-model="formData0.platformLeader.sex">
                  </t-select>
                </t-form-item>
                <t-form-item label="身份证号" name="platformLeader.idCard">
                  <t-input style="width: 390px" placeholder="请输入身份证号" clearable
                    v-model="formData0.platformLeader.idCard"></t-input>
                </t-form-item>
                <t-form-item label="出生年月" name="platformLeader.birthDate">
                  <t-date-picker placeholder="请选择生日" v-model="formData0.platformLeader.birthDate" :disable-date="{
                    after: dayjs().endOf('month').add(-18, 'year').format()
                  }" style="width: 390px"></t-date-picker>
                </t-form-item>
                <!-- <t-form-item label="联系电话" name="platformLeader.telephone">
                  <t-input style="width: 390px" placeholder="请输入电话号码" clearable
                    v-model="formData0.platformLeader.telephone"></t-input>
                </t-form-item> -->
                <t-form-item label="手机号码" name="platformLeader.phone">
                  <t-input style="width: 390px" placeholder="请输入手机号码" clearable
                    v-model="formData0.platformLeader.phone"></t-input>
                </t-form-item>
                <t-form-item label="电子信箱" name="platformLeader.email">
                  <t-input style="width: 390px" clearable v-model="formData0.platformLeader.email"></t-input>
                </t-form-item>
                <t-form-item label="学历" name="platformLeader.education">
                  <t-select style="width: 390px" v-model="formData0.platformLeader.education" clearable
                    placeholder="请选择学历" :options="dict.type.education">
                  </t-select>
                </t-form-item>
              </t-col>
              <t-col :span="6">
                <t-form-item label="专业" name="platformLeader.majorName">
                  <t-input v-model="formData0.platformLeader.majorName" clearable placeholder="请输入专业"
                    style="width: 390px" />
                </t-form-item>
                <t-form-item label="职务" name="platformLeader.duty">
                  <t-input style="width: 390px" clearable v-model="formData0.platformLeader.duty"></t-input>
                </t-form-item>
                <t-form-item label="技术职称" name="platformLeader.profTitId">
                  <t-tree-select clearable @change="onProfTitIdChange" filterable style="width: 390px"
                    :treeProps="{ keys: { value: 'id' }, valueMode: 'onlyLeaf' }"
                    v-model="formData0.platformLeader.profTitId" :data="profTitOptions"
                    placeholder="职称"></t-tree-select>
                  <!--                    <t-input style="width: 390px" clearable v-model="formData0.projectLeader.profTitId"-->
                  <!--                    ></t-input>-->
                </t-form-item>
                <t-form-item label="职称" name="platformLeader.profTit">
                  <t-select disabled style="width: 390px" v-model="formData0.platformLeader.profTit" clearable
                    placeholder="请选择职称" :options="dict.type.prof_tit">
                  </t-select>
                </t-form-item>
                <t-form-item label="所在单位" name="platformLeader.workUnit">
                  <t-tree-select clearable filterable style="width: 390px" :treeProps="{ keys: { value: 'id' } }"
                    v-model="formData0.platformLeader.workUnit" :data="deptMenuOptions"
                    placeholder="选择所在单位"></t-tree-select>
                </t-form-item>
                <t-form-item label="年累计在平台工作时间(月)" name="platformLeader.workMonth">
                  <t-input-number :allowInputOverLimit="false" v-model='formData0.platformLeader.workMonth' :min="1" />
                </t-form-item>
              </t-col>
            </t-row>
          </t-card>
        </t-col>
      </t-row>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button v-if="!getPlatformId" theme="primary" type="submit">提交申请</t-button>
          <t-button v-else theme="primary" type="submit">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!-- 平台主要人员 -->
    <t-form ref="form" :key="activeForm" :colon="true" labelAlign="top" v-if="activeForm === 1" class="step-form"
      :data="formData1" @submit="onSubmit1" :rules="rules1">
      <t-form-item label="" name="platformMember">
        <platform-main-member ref="platform-main-member" v-model="formData1.platformMember" :editOpen="true"
          class="description"></platform-main-member>
      </t-form-item>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button @click="onCurChanged(0)" theme="default" variant="base">上一步</t-button>
          <t-button theme="primary" type="submit">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!-- 现有仪器及设备一览表（20万元以上） -->
    <t-form ref="form" :key="activeForm" :colon="true" labelAlign="top" v-if="activeForm === 2" class="step-form"
      :data="formData2" @submit="onSubmit2" :rules="rules2">
      <t-form-item label="仪器设备" name="Equipments">
        <platform-device ref="platform-device" v-model="formData2.Equipments" :editOpen="true"
          :value="formData2.Equipments"></platform-device>
      </t-form-item>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button @click="onCurChanged(1)" theme="default" variant="base">上一步</t-button>
          <t-button theme="primary" type="submit">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!-- 管理委员会成员 -->
    <t-form ref="form" :key="activeForm" :colon="true" labelAlign="top" v-if="activeForm === 3" class="step-form"
      :data="formData3" @submit="onSubmit3" :rules="rules3">
      <t-form-item label="" name="platformMember">
        <platform-manager-member ref="platform-manager-member" v-model="formData3.platformMember" :editOpen="true"
          class="description"></platform-manager-member>
      </t-form-item>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button @click="onCurChanged(2)" theme="default" variant="base">上一步</t-button>
          <t-button theme="primary" type="submit">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!-- 学术委员会成员 -->
    <t-form ref="form" :key="activeForm" :colon="true" labelAlign="top" v-if="activeForm === 4" class="step-form"
      :data="formData4" @submit="onSubmit4" :rules="rules4">
      <t-form-item label="" name="platformMember">
        <platform-study-member ref="platform-study-member" v-model="formData4.platformMember" :editOpen="true"
          class="description"></platform-study-member>
      </t-form-item>
      <t-row>
        <t-col :span="11" class="query-form-inline">
          <t-button @click="onCurChanged(3)" theme="default" variant="base">上一步</t-button>
          <t-button theme="primary" type="submit">下一步</t-button>
        </t-col>
        <t-col :span="1" class="operation-container">
          <t-button variant="outline" @click="close">返回</t-button>
        </t-col>
      </t-row>
    </t-form>
    <!--     附件-->
    <t-form ref="form" :key="activeForm" :colon="true" labelAlign="top" v-if="activeForm === 5" class="step-form"
      :data="formData5">
      <t-form-item name="fileUpload" label="上传申报相关文件" labelAlign="top" style="margin-bottom: 10px">
        <t-table row-key="id" :columns="projectFileColumns" :data="projectFileData">
          <template #id="{ row, rowIndex }">
            {{ rowIndex + 1 }}
          </template>
          <template #op="{ row }">
            <file-upload :tips="row.tips" :accept="row.accept" v-model="row.fileIds" :moduleKey="row.moduleKey"
              :fileList="row.fileLists" :multiple="true">
              <t-button variant="outline">
                <t-icon name="cloud-upload" slot="icon" />
                点击上传
              </t-button>
            </file-upload>
          </template>
          <template #c1="{ row }">
            <a v-if="row.c3" class="t-button-link" :href="`${file_domain}/${row.c3}`" target="_blank">{{ row.c1 }}</a>
            <div v-else>{{ row.c1 }}</div>
          </template>
        </t-table>
      </t-form-item>
      <t-row>
        <t-col :span="10" class="query-form-inline">
          <t-button :disabled="isCommit" type="reset" @click="onCurChanged(4)" theme="default" variant="base">上一步
          </t-button>
          <t-button :disabled="isCommit" theme="primary" @click="onSubmit6()" type="submit">暂存</t-button>
        </t-col>
        <t-col :span="2" class="operation-container">
          <t-tooltip content="提交后不可再编辑会进入审批流程">
            <t-button :disabled="isCommit" theme="primary" @click="onSubmit5()" type="submit">提交到单位管理员</t-button>
          </t-tooltip>
        </t-col>
      </t-row>
    </t-form>
  </div>
</template>

<script>
import { VITE_FILE_DOMAIN } from '@/api/upload'
import contractTerms from "./components/contract-terms.vue";
import TinyMceEditor from "@/components/TinyMceEditor/index.vue";
import PlatformDevice from "./components/platform-device.vue";
import platformBudget from "@/pages/kjpt/platform/components/platform-budget.vue";
import platformMainMember from "./components/platform-main-member.vue";
import platformManagerMember from "./components/platform-manager-member.vue";
import platformStudyMember from "./components/platform-study-member.vue";
import platformMember from "@/pages/kjpt/components/platform-member.vue";
import platformMemberTechnology from "@/pages/kjpt/components/platform-member-technology.vue";
import FileUpload from "@/components/FileUpload/index.vue"
import { TODAY } from '@/utils/date';
import dayjs from "dayjs";
import { getDictList } from "@/api/system/dict/data";
import { getFiles } from "@/api/common";

export default {
  name: "platform-apply",
  dicts: ["platform_status", "platform_category", "platform_technical_field", "construction_mode", "declaration_method", "kjpt_owning_subject", "kjpt_key_word", "project_type", "subject_classification", "sys_user_sex", "prof_tit", "degree", "education", "duty", "platform_type", "expect_result_type", "platform_level", "research_direction"],
  components: {
    TinyMceEditor,
    PlatformDevice,
    platformBudget,
    platformMember,
    platformMemberTechnology,
    FileUpload,
    contractTerms,
    platformMainMember,
    platformManagerMember,
    platformStudyMember
  },
  data () {
    return {
      deptMenuOptions: [],
      projectFileData: [
        {
          id: 1,
          c1: "实验室人员表（依托单位盖章扫描上传）",
          c2: "是",
          moduleKey: "kjptsysryb",
          require: true,
          fileIds: [],
          fileLists: [],
          tips: "限制pdf、图片",
          accept: "application/pdf,image/*"
        },
        {
          id: 2,
          c1: "组建方案（签字盖章扫描上传）",
          c2: "是",
          moduleKey: "kjptzjfa",
          require: true,
          fileIds: [],
          fileLists: [],
          tips: "限制pdf、图片",
          accept: "application/pdf,image/*"
        },
        {
          id: 3,
          c1: "合作协议（签字盖章扫描上传，有共建单位的必备）",
          c2: "是",
          moduleKey: "kjpthzxy",
          require: true,
          fileIds: [],
          fileLists: [],
          tips: "限制pdf、图片",
          accept: "application/pdf,image/*"
        },
        {
          id: 4,
          c1: "牵头单位基础条件及成效表（上传excel表格）",
          c2: "是",
          moduleKey: "kjptqtdwjctj",
          require: true,
          fileIds: [],
          fileLists: [],
          tips: "限制pdf、excel",
          accept: "application/pdf,.xlsx,.xls"
        },
        {
          id: 5,
          c1: "其他",
          c2: "是",
          moduleKey: "kjptqt",
          require: true,
          fileIds: [],
          fileLists: [],
          tips: "限制pdf、图片",
          accept: "application/pdf,image/*"
        },
      ],
      projectFileColumns: [
        {
          colKey: "id",
          title: "序号",
          align: "center",
          width: 64
        },
        {
          colKey: "c1",
          title: "附件名称",
          align: "center",
        },

        {
          colKey: "c2",
          title: "是否必需",
          align: "center",
        },
        {
          colKey: "op",
          title: "操作",
          align: "left",
        },
      ],
      dictTypes: {},
      applyLoading: false,
      keyWord: [],
      nameOptions: [],
      nameOptions2: [],
      nameOptions3: [],
      leaderLoading: false,
      leaderLoading2: false,
      leaderLoading3: false,
      maxlength: 1000,
      dayjs,
      site_tag: import.meta.env.VITE_SITE_TAG,
      file_domain: VITE_FILE_DOMAIN,
      projectCategoryColumns: [
        {
          colKey: "name",
          title: "类别名称",
        },
        {
          colKey: 'row-select',
          type: 'single',
          title: "选择",
          width: 64,
          checkProps: ({ row }) => ({ disabled: row.children && row.children.length > 0 }),
        },
        {
          colKey: "categoryType",
          title: "类型",
          align: "center",
          width: 100
        },
        {
          colKey: "startDate",
          title: "申报开始时间",
          align: "center",
          width: 200
        },
        {
          colKey: "endDate",
          title: "申报结束时间",
          align: "center",
          width: 200
        },
        {
          colKey: "applyStatus",
          title: "申报状态",
          align: "center",
          width: 200
        },
        {
          colKey: 'note',
          title: "描述",
          ellipsis: true
        },
      ],
      // projectFileData: [
      //   {
      //     id: 1,
      //     c1: "查新报告",
      //     c2: "是",
      //     moduleKey: "projectCXBG",
      //     fileIds: [],
      //     fileLists: [],
      //   },
      //   {
      //     id: 2,
      //     c1: "归口管理单位科研诚信承诺书",
      //     c2: "是",
      //     fileIds: [],
      //     fileLists: [],
      //     moduleKey: "projectCNS"
      //   },
      //   {
      //     id: 3,
      //     c1: "项目组科研诚信承诺书",
      //     c2: "是",
      //     fileIds: [],
      //     fileLists: [],
      //     moduleKey: "projectTeamCNS"
      //   }
      // ],
      // projectFileColumns: [
      //   {
      //     colKey: "id",
      //     title: "序号",
      //     align: "center",
      //     width: 64
      //   },
      //   {
      //     colKey: "c1",
      //     title: "附件名称",
      //     align: "center",
      //   },
      //   {
      //     colKey: "c2",
      //     title: "是否必需",
      //     align: "center",
      //   },
      //   {
      //     colKey: "op",
      //     title: "操作",
      //     align: "left",
      //   },
      // ],
      selectedProjectCategoryRowKeys: [],
      isCommit: false,
      profTitOptions: [],
      menuOptions: [],
      deptMenuOptions: [],
      // selectedResearchPlanRowKeys: [],
      formData5: {
      },
      taskId: null,
      tabValue: "0",
      activeForm: null,
      formData1: {
        "platformMember": [],
      },
      rules1: {
        platformMember: [
          {
            required: true,
            message: "平台主要人员不能为空",
          },
        ],
      },
      currentDeptName: '',
      formData0: {
        name: '',
        platformCategory: '',
        technicalField: '',
        constructionMode: '',
        declarationMethod: '',
        declarationDate: '',
        manageDept: '',
        deptName: '',
        address: "",
        postCode: "",
        serviceIndustry: '',
        owningSubject: '',
        startDate: '',
        content: "",
        researchDirections: [],
        platformLeader: {
          name: '',
          sex: '',
          birthDate: '',
          // telephone: '',
          idCard: "",
          phone: "",
          email: '',
          education: '',
          majorName: '',
          duty: '',
          profTitId: '',
          profTit: '',
          workUnit: '',
          workMonth: ''
        },
        platformLinker: {
          name: '',
          phone: '',
          email: '',
        },
      },
      rules0: {
        // 基本信息
        keyWord: [{ required: true, validator: (val) => val && val.length, message: "关键词不能为空", type: "error" }],
        researchDirections: [{ required: true, validator: (val) => val && val.length, message: "平台主要研究方向不能为空", type: "error" }],
        name: [
          {
            required: true,
            message: "平台名称不能为空",
          },
        ],
        technicalField: [
          { required: true, message: "技术领域不能为空", type: "error" }
        ],
        platformCategory: [
          { required: true, message: "平台类型不能为空", type: "error" }
        ],
        constructionMode: [
          { required: true, message: "组建方式不能为空", type: "error" }
        ],
        declarationMethod: [
          { required: true, message: "申报方式不能为空", type: "error" }
        ],
        address: [
          {
            required: true,
            message: "地址不能为空",
          },
        ],
        postCode: [
          {
            required: true,
            message: "邮编不能为空",
          },
        ],
        declarationDate: [
          {
            required: true,
            message: "申报日期不能为空",
          },

        ],
        manageDept: [
          {
            required: true,
            message: "主管部门不能为空",
          },
        ],
        owningSubject: [
          {
            required: true,
            message: "平台研究方向所属学科不能为空",
          },
        ],
        serviceIndustry: [
          {
            required: true,
            message: "平台服务行业不能为空",
          },
        ],
        startDate: [
          {
            required: true,
            message: "项目开始日期不能为空",
          },
        ],
        intro: [
          {
            required: true,
            message: "平台建设内容不能为空",
          },
        ],
        // platformLinker（联系人）
        'platformLinker.name': [
          {
            required: true,
            message: "项目联系人姓名不能为空",
          },
        ],
        'platformLinker.phone': [
          {
            required: true,
            message: "联系人电话不能为空",
          },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "联系人电话请输入正确的手机号码",
          },
        ],

        'platformLinker.email': [
          {
            required: true,
            message: "联系人邮箱不能为空",
          },
          { email: { ignore_max_length: true }, message: '请输入正确的邮箱地址' }
        ],

        // platformLeader（平台负责人）
        'platformLeader.name': [
          {
            required: true,
            message: "平台负责人姓名不能为空",
          },
        ],
        'platformLeader.sex': [
          {
            required: true,
            message: "平台主要负责人性别不能为空",
          },
        ],
        'platformLeader.idCard': [
          {
            required: true,
            message: "平台主要负责人身份证不能为空",
          },
          {
            message: "身份证号不正确",
            pattern: /^\d{6}((((((19|20)\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|(((19|20)\d{2})(0[13578]|1[02])31)|((19|20)\d{2})02(0[1-9]|1\d|2[0-8])|((((19|20)([13579][26]|[2468][048]|0[48]))|(2000))0229))\d{3})|((((\d{2})(0[13-9]|1[012])(0[1-9]|[12]\d|30))|((\d{2})(0[13578]|1[02])31)|((\d{2})02(0[1-9]|1\d|2[0-8]))|(([13579][26]|[2468][048]|0[048])0229))\d{2}))(\d|X|x)$/,
          },
        ],
        'platformLeader.birthDate': [
          {
            required: true,
            message: "平台主要负责人生日不能为空",
          },

        ],
        // 'platformLeader.telephone': [
        //   {
        //     required: true,
        //     message: "平台主要负责人联系电话不能为空",
        //   },
        //   {
        //     pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
        //     message: "请输入正确的手机号码",
        //   },
        // ],
        'platformLeader.phone': [
          {
            required: true,
            message: "平台主要负责人联系手机号码不能为空",
          },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
          },
        ],
        'platformLeader.email': [
          {
            required: true,
            message: "平台主要负责人邮箱不能为空",
          },
          { email: { ignore_max_length: true }, message: '请输入正确的邮箱地址' }
        ],
        'platformLeader.education': [
          {
            required: true,
            message: "平台主要负责人学历不能为空",
          },
        ],
        'platformLeader.majorName': [
          {
            required: true,
            message: "平台主要负责人所学专业不能为空",
          },
        ],
        'platformLeader.profTitId': [
          {
            required: true,
            message: "平台主要负责人职称不能为空",
          },
        ],
        'platformLeader.duty': [
          {
            required: true,
            message: "平台主要负责人职务不能为空",
          },
        ],
        'platformLeader.profTit': [
          {
            required: true,
            message: "平台主要负责人职称名字不能为空",
          },
        ],
        'platformLeader.workUnit': [
          {
            required: true,
            message: "所在单位不能为空",
          },
        ],
        'platformLeader.workMonth': [
          {
            required: true,
            message: "年累计在平台工作时间不能为空",
          },
        ],

      },
      rules2: {
        Equipments: [
          {
            required: true,
            message: "现有仪器及设备一览表不能为空",
          },
        ],
      },
      formData3: {
        "platformMember": [],
      },

      rules3: {
        platformMember: [
          {
            required: true,
            message: "管理委员会成员不能为空",
          },
        ],
      },
      rules4: {
        platformMember: [
          {
            required: true,
            message: "学术委员会成员不能为空",
          },
        ],
      },
      formData4: {
        "platformMember": [],
      },
      formData2: {
        Equipments: []
      }
    }
  },
  watch: {
    activeForm: {
      immediate: true,
      handler (val) {
        const targetEle = document.getElementById("main")
        if (targetEle) {
          const { pos, top } = targetEle.style;
          targetEle.style.position = 'relative';
          targetEle.style.top = '-100px';
          targetEle.scrollIntoView({ behavior: 'smooth', block: 'start', inline: "nearest" });
          targetEle.style.top = top;
          targetEle.style.position = pos;
        }
      }
    }
  },
  async created () {
    this.getUserInfo()
    this.getDeptTreeSelect()
    await this.getDataTypes()

    await Promise.all([this.getDeptTreeSelect(this.$store.state.user.deptId), this.getProfTitTreeSelect(),]);
    const taskId = this.$route.params && this.$route.params.taskId;

    if (!taskId) {
      this.$message.error("任务id丢失返回项目");
      this.$router.push("/kjpt/platform/platform-my");
    }
    this.taskId = taskId;
    this.$api.kjpt.project.getPlatformMemberNoType(taskId).then(response => {
      if (response.data !== null && response.data.length > 0) {
        sessionStorage.setItem(`${this.taskId}-platform-memberId`, taskId)
      }
    }).catch((e) => {
      this.applyLoading = false;
    });
    this.$api.kjpt.project.getAll(taskId).then(response => {
      if (response.data !== null) {
        response.data.projectLeader = response.data.projectLeader ? response.data.projectLeader : this.formData0.projectLeader;
        this.formData0 = response.data;
        // console.log('this.formData0------', this.formData0);
        // console.log('this.taskId------', this.taskId);

        sessionStorage.setItem(`${this.taskId}-platform-platformId`, taskId)
        if (response.data.platformMembers && response.data.platformMembers.length > 0) {

          sessionStorage.setItem(`${this.taskId}-platform-unitId`, taskId)
        }
        if (response.data.platformEquipments && response.data.platformEquipments.length > 0) {
          sessionStorage.setItem(`${this.taskId}-platform-equipmentId`, taskId)
        }
        if (response.data.platformManageOrgs && response.data.platformManageOrgs.length > 0) {
          sessionStorage.setItem(`${this.taskId}-platform-backgroundId`, taskId)
        }
        if (response.data.platformManageSciences && response.data.platformManageSciences.length > 0) {
          sessionStorage.setItem(`${this.taskId}-platform-budgetId`, taskId)

          getFiles(taskId).then((res) => {
            if (res.data && res.data.length) {
              sessionStorage.setItem(`${this.taskId}-platform-fileId`, taskId)
            }

          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        }

      }
      const activeForm = Number(sessionStorage.getItem(`${taskId}-platform-activeForm`)) || 0;
      // console.log("activeForm", activeForm)
      this.onCurChanged(activeForm, 0);
    }).catch((e) => {
      this.applyLoading = false;
      this.$message.error(e.toString());
    });


  },
  methods: {
    getDeptTreeSelect () {
      return this.$api.system.dept.treeSelectAllIn().then(response => {
        this.deptMenuOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getUserInfo () {
      this.$api.system.user.getBaseInfo().then(response => {
        this.currentDeptName = response.data.dept.deptName;
        this.formData0.platformLeader.workUnit = response.data.dept.id;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDataTypes () {
      return getDictList(["prof_tit"]).then(response => {
        this.dictTypes = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    createKeyWordOptions (value) {
      this.dict.type.kjpt_key_word.push({
        label: `${value}`,
        value,
      });
    },
    createProjectLeaderOptions (value) {
      this.nameOptions.push({
        label: `${value}`,
        value,
        name: value
      });
    },
    createProjectLeaderOptions2 (value) {
      this.nameOptions2.push({
        label: `${value}`,
        value,
        name: value
      });
    },
    remoteProjectLeaderMethod (search) {
      this.leaderLoading = true;
      this.$api.system.member.searchList({ name: search }).then(response => {
        this.nameOptions = response.data.map(val => ({
          ...val,
          label: `${val.name}-${val.idCard}`,
          value: `${val.name}-${val.idCard}`,
        }));
        this.leaderLoading = false;
      }).catch((e) => {
        this.leaderLoading = false;
        this.$message.error(e.toString());
      });
    },
    remoteProjectLeaderMethod2 (search) {
      this.leaderLoading2 = true;
      this.$api.system.member.searchList({ name: search }).then(response => {
        this.nameOptions2 = response.data.map(val => ({
          ...val,
          label: `${val.name}-${val.idCard}`,
          value: `${val.name}-${val.idCard}`,
        }));
        this.leaderLoading2 = false;
      }).catch((e) => {
        this.leaderLoading2 = false;
        this.$message.error(e.toString());
      });
    },

    onLeaderNameChange (val, content) {
      console.log("change")
      const index = this.nameOptions.findIndex(val => content?.option?.id === val.id)
      this.nameOptions[index].label = this.nameOptions[index].name;
      this.$set(this.nameOptions, index, this.nameOptions[index])
      // Object.assign(this.formData0.projectLeader, content.option)
      const oldId = this.formData0.id;
      const platformLeaderID = this.formData0.platformLeader.id
      // const { telephone } = this.formData0.platformLeader
      const { phone } = this.formData0.platformLeader
      const { email } = this.formData0.platformLeader
      // this.formData0.platformLeader = content.option || this.nameOptions[index]
      const obj = {
        phone: this.formData0.platformLeader.phone,
        email: this.formData0.platformLeader.email
      }
      Object.assign(this.formData0.platformLeader, content.option || this.nameOptions[index], obj)
      this.formData0.id = oldId;
      this.formData0.platformLeader.id = platformLeaderID
      // this.formData0.platformLeader.telephone = ""
      // this.formData0.platformLeader.telephone = telephone
      // this.formData0.platformLeader.phone = phone
      // this.formData0.platformLeader.email = email
    },
    onLeaderNameChange2 (val, content) {
      // console.log('----------', val, content);

      const index = this.nameOptions2.findIndex(val => content?.option?.id === val.id)
      this.nameOptions2[index].label = this.nameOptions2[index].name;
      this.$set(this.nameOptions2, index, this.nameOptions2[index])

      // Object.assign(this.formData0.projectLeader, content.option)
      // const oldId = this.formData0.id;

      // this.formData0.platformLinker = content.option || this.nameOptions2[index]

      this.formData0.platformLinker.name = content.option.name
      this.formData0.platformLinker.phone = content.option.phone
      this.formData0.platformLinker.email = content.option.email
      // this.formData0.id = oldId;
    },

    onProfTitIdChange (val) {
      this.$api.system.profTit.get(val).then(response => {
        this.formData0.platformLeader.profTit = response.data.level;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },

    getProfTitTreeSelect () {
      return this.$api.system.profTit.treeselect().then(response => {
        this.profTitOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    getDeptTreeSelect () {
      return this.$api.system.dept.treeSelectAllIn().then(response => {
        this.deptMenuOptions = response.data;
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
    close () {
      this.applyLoading = false;
      setTimeout(() => {
        this.$tab.closeOpenPage({ path: "/kjpt/platform/platform-my" });
      }, 1000)
    },
    onCurChanged (cur, pre) {
      console.log('cur---------', cur)
      if (Number(cur) === 1) {
        if (!sessionStorage.getItem(`${this.taskId}-platform-platformId`)) {
          this.$message.error("基本信息还未提交")
          return false;
        }
      } else if (Number(cur) === 2) {
        if (!sessionStorage.getItem(`${this.taskId}-platform-unitId`) && !sessionStorage.getItem(`${this.taskId}-platform-equipmentId`)) {
          this.$message.error("平台主要人员还未提交")
          return false;
        }
      } else if (Number(cur) === 3) {
        if (!sessionStorage.getItem(`${this.taskId}-platform-equipmentId`) && !sessionStorage.getItem(`${this.taskId}-platform-backgroundId`)) {
          this.$message.error("现有仪器及设备一览表还未提交");
          return false;
        }
      } else if (Number(cur) === 4) {
        if (!sessionStorage.getItem(`${this.taskId}-platform-backgroundId`) && !sessionStorage.getItem(`${this.taskId}-platform-budgetId`)) {
          this.$message.error("管理委员会成员还未提交");
          return false;
        }
      } else if (Number(cur) === 5) {
        if (!sessionStorage.getItem(`${this.taskId}-platform-budgetId`) && !sessionStorage.getItem(`${this.taskId}-platform-memberId`)) {
          this.$message.error("学术委员会成员还未提交");
          return false;
        }
      } else if (Number(cur) === 6) {
        if (!sessionStorage.getItem(`${this.taskId}-platform-memberId`) && !sessionStorage.getItem(`${this.taskId}-platform-fileId`)) {
          this.$message.error("相关附件还未提交");
          return false;
        }
      }

      this.applyLoading = true;
      if (Number(cur) === 0) {
        if (sessionStorage.getItem(`${this.taskId}-platform-platformId`)) {
          const platformId = Number(sessionStorage.getItem(`${this.taskId}-platform-platformId`));
          this.$api.kjpt.project.get(platformId).then(response => {
            response.data.projectLeader = response.data.projectLeader ? response.data.projectLeader : this.formData0.projectLeader;
            this.formData0 = response.data;
            this.activeForm = cur;
            sessionStorage.setItem(`${this.taskId}-platform-activeForm`, cur);
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-platform-activeForm`, cur);
          this.applyLoading = false;
        }

      } else if (Number(cur) === 1) {

        if (sessionStorage.getItem(`${this.taskId}-platform-unitId`)) {

          const unitId = Number(sessionStorage.getItem(`${this.taskId}-platform-unitId`));

          this.$api.kjpt.project.getPlatformMemberNoType(unitId).then(response => {

            this.formData1.platformMember = response.data
            this.activeForm = cur;
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-platform-activeForm`, cur);
          this.applyLoading = false;
        }

      } else if (Number(cur) === 2) {
        if (sessionStorage.getItem(`${this.taskId}-platform-equipmentId`)) {
          const equipmentId = Number(sessionStorage.getItem(`${this.taskId}-platform-equipmentId`));
          this.$api.kjpt.project.getByPlatformId(equipmentId).then(response => {
            this.formData2.Equipments = response.data;
            this.activeForm = cur;
            sessionStorage.setItem(`${this.taskId}-platform-activeForm`, cur);
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-platform-activeForm`, cur);
          this.applyLoading = false;
        }

      } else if (Number(cur) === 3) {
        if (sessionStorage.getItem(`${this.taskId}-platform-backgroundId`)) {
          const equipmentId = Number(sessionStorage.getItem(`${this.taskId}-platform-backgroundId`));
          this.$api.kjpt.project.getManageOrgByPlatformId(equipmentId).then(response => {
            this.formData3.platformMember = response.data
            this.activeForm = cur;
            // sessionStorage.setItem(`${this.taskId}-platform-activeForm`, cur);
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-platform-activeForm`, cur);
          this.applyLoading = false;
        }
      } else if (Number(cur) === 4) {
        if (sessionStorage.getItem(`${this.taskId}-platform-budgetId`)) {
          const budgetId = Number(sessionStorage.getItem(`${this.taskId}-platform-budgetId`));
          this.$api.kjpt.project.getManageScienceByPlatformId(budgetId).then(response => {
            this.formData4.platformMember = response.data;
            this.activeForm = cur;
            // sessionStorage.setItem(`${this.taskId}-platform-activeForm`, cur);
            this.applyLoading = false;
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-platform-activeForm`, cur);
          this.applyLoading = false;
        }
      } else if (Number(cur) === 5) {

        if (sessionStorage.getItem(`${this.taskId}-platform-fileId`)) {

          getFiles(this.getPlatformId()).then((res) => {
            this.activeForm = cur;
            const files = {}
            res.data.forEach((item) => {
              if (!files[item.moduleKey]) {
                files[item.moduleKey] = []
              }
              files[item.moduleKey].push({
                name: item.fileName,
                url: item.fullFilePath,
                id: item.id,
                filePath: item.filePath
              })
            })
            this.projectFileData[0].fileLists = files.kjptsysryb || [];
            this.projectFileData[0].fileIds = files.kjptsysryb?.map(val => val.id) || [];

            this.projectFileData[1].fileLists = files.kjptzjfa || [];
            this.projectFileData[1].fileIds = files.kjptzjfa?.map(val => val.id) || [];

            this.projectFileData[2].fileLists = files.kjpthzxy || [];
            this.projectFileData[2].fileIds = files.kjpthzxy?.map(val => val.id) || [];

            this.projectFileData[3].fileLists = files.kjptqtdwjctj || [];
            this.projectFileData[3].fileIds = files.kjptqtdwjctj?.map(val => val.id) || [];

            this.projectFileData[4].fileLists = files.kjptqt || [];
            this.projectFileData[4].fileIds = files.kjptqt?.map(val => val.id) || [];
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
          this.applyLoading = false;
        } else {
          this.activeForm = cur;
          sessionStorage.setItem(`${this.taskId}-platform-activeForm`, cur);
          this.applyLoading = false;
        }
      } else {
        this.activeForm = cur;
        sessionStorage.setItem(`${this.taskId}-platform-activeForm`, cur);
        this.applyLoading = false;
      }
    },
    getPlatformId () {
      return sessionStorage.getItem(`${this.taskId}-platform-platformId`)
    },
    isSubmit (name) {
      // console.log('platform-memberId---------', sessionStorage.getItem(`${this.taskId}-platform-memberId`))
      return sessionStorage.getItem(`${this.taskId}-platform-${name}`) ? '已提交' : '未提交';
    },
    onSubmit0 ({ validateResult, firstError }) {
      const isValidate = this.$refs["contract-terms"].checkData()
      if (!isValidate) {
        return false;
      }

      if (validateResult === true) {

        this.applyLoading = true;
        if (!sessionStorage.getItem(`${this.taskId}-platform-platformId`)) {
          this.$api.kjpt.project.add({
            ...this.formData0,
            // platformStatus: '1',
          }).then(response => {
            sessionStorage.setItem(`${this.taskId}-platform-platformId`, response.data.id)
            this.$message.success('提交成功');
            this.onCurChanged(1)
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.$api.kjpt.project.edit({
            ...this.formData0,
            // platformStatus: '1',
          }).then(response => {
            this.$message.success('修改成功');
            this.onCurChanged(1)
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        }
      } else {
        this.$message.error(firstError);
      }
    },
    onSubmit1 ({ validateResult, firstError }) {
      if (validateResult === true) {
        const isValidate = this.$refs["platform-main-member"].checkData();
        if (!isValidate) {
          return false;
        }
        this.formData1.platformMember.forEach(item => {
          item.type = "1"
          item.platformId = Number(sessionStorage.getItem(`${this.taskId}-platform-platformId`));
        })

        let subArr = []
        subArr = [...this.formData1.platformMember]
        this.applyLoading = true;

        // if (!sessionStorage.getItem(`${this.taskId}-platform-unitId`)) {
        this.$api.kjpt.project.platformMemberAdd(subArr).then(response => {
          this.applyLoading = false;
          sessionStorage.setItem(`${this.taskId}-platform-unitId`, Number(sessionStorage.getItem(`${this.taskId}-platform-platformId`)))
          this.$message.success('提交成功');
          this.onCurChanged(2);
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });

        // } else {
        // this.$api.kjpt.project.constructionUnitUpdate({
        //   ...this.formData1,
        //   id: Number(sessionStorage.getItem(`${this.taskId}-platform-unitId`))
        // }).then(response => {
        //   this.$message.success('提交成功');
        //   this.onCurChanged(2);
        // }).catch((e) => {
        //   this.applyLoading = false;
        //   this.$message.error(e.toString());
        // });
        // }


      } else {
        this.$message.error(firstError);
      }
    },
    onSubmit2 ({ validateResult, firstError }) {
      if (validateResult === true) {
        const isValidate = this.$refs["platform-device"].checkData();
        if (!isValidate) {
          return false;
        }
        for (let i = 0; i < this.formData2.Equipments.length; i++) {
          this.formData2.Equipments[i].platformId = Number(sessionStorage.getItem(`${this.taskId}-platform-platformId`));
        }
        this.applyLoading = true;
        if (!sessionStorage.getItem(`${this.taskId}-platform-equipmentId`)) {
          this.$api.kjpt.project.platformEquipmentAddList(this.formData2.Equipments).then(response => {
            sessionStorage.setItem(`${this.taskId}-platform-equipmentId`, Number(sessionStorage.getItem(`${this.taskId}-platform-platformId`)))
            this.$message.success('提交成功');
            this.onCurChanged(3);
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        } else {
          this.$api.kjpt.project.platformEquipmentAddList(this.formData2.Equipments).then(response => {
            this.$message.success('提交成功');
            this.onCurChanged(3);
          }).catch((e) => {
            this.applyLoading = false;
            this.$message.error(e.toString());
          });
        }

      } else {
        this.$message.error(firstError);
      }
    },
    onSubmit3 ({ validateResult, firstError }) {
      if (validateResult === true) {

        const isValidate = this.$refs["platform-manager-member"].checkData();
        if (!isValidate) {
          return false;
        }
        this.formData3.platformMember.forEach(item => {
          item.type = "1"
          item.platformId = Number(sessionStorage.getItem(`${this.taskId}-platform-platformId`));
        })
        // 增加note字段
        for (const item in this.formData3) {
          this.formData3[item].forEach((i, index) => {
            if (!i.hasOwnProperty("note")) {
              this.formData3[item][index].note = ""
            }
          })
        }
        let subArr = []
        subArr = [...this.formData3.platformMember]
        this.applyLoading = true;

        this.$api.kjpt.project.platformManageOrgAddList(subArr).then(response => {
          this.applyLoading = false;
          sessionStorage.setItem(`${this.taskId}-platform-backgroundId`, Number(sessionStorage.getItem(`${this.taskId}-platform-platformId`)))
          this.$message.success('提交成功');
          this.onCurChanged(4);
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });


      } else {
        this.$message.error(firstError);
      }
    },
    onSubmit4 ({ validateResult, firstError }) {
      if (validateResult === true) {
        const isValidate = this.$refs["platform-study-member"].checkData();
        if (!isValidate) {
          return false;
        }
        this.formData4.platformMember.forEach(item => {
          item.platformId = Number(sessionStorage.getItem(`${this.taskId}-platform-platformId`));
        })

        let subArr = []
        subArr = [...this.formData4.platformMember]
        this.applyLoading = true;

        this.$api.kjpt.project.platformManageScienceAddList(subArr).then(response => {
          this.applyLoading = false;
          sessionStorage.setItem(`${this.taskId}-platform-budgetId`, Number(sessionStorage.getItem(`${this.taskId}-platform-platformId`)))
          this.$message.success('提交成功');
          this.onCurChanged(5);
        }).catch((e) => {
          this.applyLoading = false;
          this.$message.error(e.toString());
        });


      } else {
        this.$message.error(firstError);
      }
    },

    onSubmit5 () {
      const isValidate = this.projectFileData.every(val => {
        if (val.require && val.fileIds.length <= 0) {
          this.$message.error(`需要上传${val.c1}`);
          return false;
        }
        return true
      })
      if (!isValidate) {
        return false
      }
      const platformId = this.getPlatformId()

      const confirmDia = this.$dialog.confirm({
        header: "提交后不可修改",
        body: `是否确认提交？`,
        theme: "warning",
        onConfirm: ({ e }) => {
          confirmDia.update({
            confirmBtn: {
              loading: true,
            },
          })

          this.applyLoading = true;
          const sysAttMainIds = []
          this.projectFileData.forEach(val => {
            sysAttMainIds.push(...val.fileIds)
          })
          this.$api.kjpt.project.submit({
            ...this.formData0,
            // platformStatus: "1",
            id: platformId,
            sysAttMainVo: {
              sysAttMainIds
            }
          }).then(val => {
            sessionStorage.setItem(`${this.taskId}-platform-fileId`, JSON.stringify(sysAttMainIds));
            this.$message.success('提交成功');
            this.applyLoading = false;
            confirmDia.destroy();
            this.close();
          }).catch((e) => {
            this.applyLoading = false;
            confirmDia.update({
              confirmBtn: {
                loading: false,
              },
            })
            this.$message.error(e.toString());
          });
        },
      })


    },
    onSubmit6 () {
      const isValidate = this.projectFileData.every(val => {
        if (val.require && val.fileIds.length <= 0) {
          this.$message.error(`需要上传${val.c1}`);
          return false;
        }
        return true
      })
      if (!isValidate) {
        return false
      }
      const platformId = this.getPlatformId()
      // const sysAttMainVo = {
      //   sysAttMainIds: this.projectFileData[0].fileIds,
      // }

      const sysAttMainIds = []
      this.projectFileData.forEach(val => {
        sysAttMainIds.push(...val.fileIds)
      })
      this.$api.kjpt.project.edit({
        ...this.formData0,
        // platformStatus: "1",
        id: platformId,
        // sysAttMainVo
        sysAttMainVo: {
          sysAttMainIds
        }
      }).then(val => {
        sessionStorage.setItem(`${this.taskId}-platform-fileId`, JSON.stringify(sysAttMainIds));
        this.$message.success('暂存成功');
        this.applyLoading = false;
        this.close();
      }).catch((e) => {
        this.applyLoading = false;
        this.$message.error(e.toString());
      });
    }
  }
}
</script>

<style lang="less" scoped>
.step-form {
  padding: 0 24px;
}

.t-row {
  margin-bottom: 14px;
}

.step-card {
  height: 100%;
  margin-bottom: 14px;
}
</style>
